home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / GNU / LIBC / STRLEN < prev   
Text File  |  1997-05-04  |  2KB  |  37 lines

  1. /* size_t strlen(const char *S)
  2.  * entry: r0 -> string
  3.  * exit: r0 = len
  4.  */
  5.  
  6. strlen:
  7.   bic     r1, r0, #3              @ addr of word containing first byte
  8.   ldr     r2, [r1], #4            @ get the first word
  9.   ands    r3, r0, #3              @ how many bytes are duff?
  10.   rsb     r0, r3, #0              @ get - that number into counter.
  11.   beq     Laligned                @ skip into main check routine if no more
  12.   orr     r2, r2, #0xFF000000     @ set this byte to non-zero
  13.   subs    r3, r3, #1              @ any more to do?
  14.   orrgt   r2, r2, #0x00FF0000     @ if so, set this byte
  15.   subs    r3, r3, #1              @ more?
  16.   orrgt   r2, r2, #0x0000FF00     @ then set.
  17. Laligned:                         @ here, we have a word in r2.  Does it
  18.   tst     r2, #0x000000FF         @ contain any zeroes?
  19.   tstne   r2, #0x0000FF00         @
  20.   tstne   r2, #0x00FF0000         @
  21.   tstne   r2, #0xFF000000         @
  22.   addne   r0, r0, #4              @ if not, the string is 4 bytes longer
  23.   ldrne   r2, [r1], #4            @ and we continue to the next word
  24.   bne     Laligned                @ 
  25. Llastword:                        @ drop through to here once we find a word
  26.   tst     r2, #0x000000FF         @ that has a zero byte in it
  27.   addne   r0, r0, #1              @ 
  28.   tstne   r2, #0x0000FF00         @ and add up to 3 bytes on to it
  29.   addne   r0, r0, #1              @
  30.   tstne   r2, #0x00FF0000         @ (if first three all non-zero, 4th must
  31.   addne   r0, r0, #1              @  be zero)
  32. #ifdef 26BIT /* is there a predefined symbol for this? */
  33.   movs    pc, r14
  34. #else /* 26BIT */
  35.   mov     pc, r14
  36. #endif /* 26BIT */
  37.